home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Metarchivos / MetafilePageUnits / MetafilePageUnits.cs next >
Encoding:
Text File  |  2002-05-27  |  2.2 KB  |  70 lines

  1. //------------------------------------------------
  2. // MetafilePageUnits.cs ⌐ 2001 by Charles Petzold
  3. //------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Imaging;
  7. using System.Drawing.Printing;     // íYa no se usa!
  8. using System.Windows.Forms;
  9.  
  10. class MetafilePageUnits: PrintableForm
  11. {
  12.      Metafile mf;
  13.  
  14.      public new static void Main()
  15.      {
  16.           Application.Run(new MetafilePageUnits());
  17.      }
  18.      public MetafilePageUnits()
  19.      {
  20.           Text = "Unidades de pßgina en metarchivos";
  21.  
  22.                // Crear el metarchivo.
  23.  
  24.           Graphics grfx  = CreateGraphics();
  25.           IntPtr ipHdc = grfx.GetHdc();
  26.  
  27.           mf = new Metafile("MetafilePageUnits.emf", ipHdc);
  28.  
  29.           grfx.ReleaseHdc(ipHdc);
  30.           grfx.Dispose();
  31.  
  32.                // Obtener el objeto Graphics para dibujar sobre el metarchivo.
  33.  
  34.           grfx = Graphics.FromImage(mf);
  35.           grfx.Clear(Color.White);
  36.  
  37.                // Dibujar en unidades de pφxeles (lßpiz de 1 punto de grosor).
  38.  
  39.           grfx.PageUnit = GraphicsUnit.Pixel;
  40.           Pen pen = new Pen(Color.Black, grfx.DpiX / 72);
  41.           grfx.DrawRectangle(pen, 0, 0, grfx.DpiX, grfx.DpiY);
  42.  
  43.                // Dibujar en unidades de 1/100 pulgadas (lßpiz de 1 punto de grosor).
  44.  
  45.           grfx.PageUnit = GraphicsUnit.Inch;
  46.           grfx.PageScale = 0.01f;
  47.           pen = new Pen(Color.Black, 100f / 72);
  48.           grfx.DrawRectangle(pen, 25, 25, 100, 100);
  49.  
  50.                // Dibujar en unidades de milφmetros (lßpiz de 1 punto de grosor).
  51.  
  52.           grfx.PageUnit = GraphicsUnit.Millimeter;
  53.           grfx.PageScale = 1;
  54.           pen = new Pen(Color.Black, 25.4f / 72);
  55.           grfx.DrawRectangle(pen, 12.7f, 12.7f, 25.4f, 25.4f);
  56.  
  57.                // Dibujar en unidades de puntos (lßpiz de 1 punto de grosor).
  58.  
  59.           grfx.PageUnit = GraphicsUnit.Point;
  60.           pen = new Pen(Color.Black, 1);
  61.           grfx.DrawRectangle(pen, 54, 54, 72, 72);
  62.  
  63.           grfx.Dispose();
  64.      }
  65.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  66.      {
  67.           grfx.DrawImage(mf, 0, 0);
  68.      }
  69. }
  70.